package com.apes.scm.account.account.model;

import com.apes.framework.jpa.DefaultPersistListener;
import com.apes.framework.jpa.Model;
import com.apes.framework.jpa.comment.Comment;
import com.apes.framework.jpa.generator.ApesGenerator;
import com.apes.framework.jpa.tuple.date.DateTime;
import com.apes.scm.masterdata.party.model.PartyRole;
import com.apes.scm.masterdata.product.model.Product;
import com.apes.scm.masterdata.stock.model.Location;
import lombok.Getter;
import lombok.Setter;
import org.hibernate.annotations.DynamicInsert;
import org.hibernate.annotations.DynamicUpdate;
import org.hibernate.annotations.SelectBeforeUpdate;

import javax.persistence.*;

/***
 * 要货数明细账
 */
@Getter
@Setter
@SelectBeforeUpdate
@DynamicInsert
@DynamicUpdate
@Entity
@EntityListeners(DefaultPersistListener.class)
@Table(name = DetailOfRequire.CONST_TABLE_NAME)
public class DetailOfRequire extends Model {
    public static final String CONST_TABLE_NAME = "acc_detailed_of_require";

    @Id
    @Column(name = "id")
    @ApesGenerator(code = CONST_TABLE_NAME, name = "要货数明细账")
    @Comment("内码")
    private Long id; //内码

    @Column(name = "source_business_type", length = 32)
    @Comment("来源单据类型")
    private String sourceBusinessType; // 来源单据类型

    @Column(name = "ORDER_NUMBER", nullable = false, length = 32)
    @Comment("单据号码")
    private String orderNumber;  //单据号码

    @Column(name = "ORDER_SERIAL_NUMBER", length = 30, nullable = false)
    @Comment("单据序号")
    private String orderSerialNumber;  //单据序号

    @Column(name = "product_require_id", nullable = false, length = 32)
    @Comment("原始要货单号")
    private String productRequire;

    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "LOCATION_ID", referencedColumnName = "id", nullable = false)
    @Comment("仓库库区编码")
    private Location location;  //仓库库区编码

    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "PRODUCT_ID", referencedColumnName = "id", nullable = false)
    @Comment("商品编码")
    private Product product;  //商品编码

    @DateTime
    @Temporal(TemporalType.TIMESTAMP)
    @Column(name = "CHANGE_TIME")
    @Comment("变动时间")
    private java.util.Date changeTime;  //变动时间

    @Column(name = "CHANGE_QTY", nullable = false, columnDefinition = "NUMBER(16,4) DEFAULT 0")
    @Comment("变动数量")
    private double changeQty = 0.0;  //变动数量

    @Column(name = "BALANCE_QTY", nullable = false, columnDefinition = "NUMBER(16,4) DEFAULT 0")
    @Comment("结存数量")
    private double balanceQty = 0.0;  //结存数量

    @Column(name = "NOTE", nullable = false, length = 256)
    @Comment("备注")
    private String remarks;  //备注

    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "COMPANY_ID", referencedColumnName = "id", nullable = false)
    @Comment("公司编码")
    private PartyRole company;  //公司编码

}
